import { defineStore } from "pinia"
import { ref } from "vue"
import { loginApi, registerApi } from "@/api/user"
import { useRouter } from "vue-router"

export const useUserStore = defineStore('user', () => {
  const router = useRouter()
  const userInfo = ref({
    id: '',
    username: '',
    password: '',
    role: '',
    name: ''
  })

  const getUserInfo = async(form) => {
    const res = await loginApi(form)
    userInfo.value = res.data
    console.log(userInfo);
    
  } 
  const setUserInfo = async(form) => {
    const res = await registerApi(form)
  }
  const clearUserInfo = () =>{
     userInfo.value = {}  
     
  }


  return {
    userInfo,
    getUserInfo,
    setUserInfo,
    clearUserInfo
  }
}, {
  persist: true,
})